/*******************************************************************************
 * Copyright (c) 2008 Sylvain Sicard.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Sylvain Sicard - initial API and implementation
 ******************************************************************************/
package fr.jade.service.fm.deployment;

import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalBindingException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;

import fr.jade.reflex.api.control.BindingNotificationController;
import fr.jade.reflex.util.Reflex;

public class CleanBindingTask extends AbstractTask {

  protected Component  client;
  protected String     clientItfName;
  
  public CleanBindingTask(Component client, String clientItfName){
    assert client != null        : "Client Task cannot be null";
    assert clientItfName != null     : "Client itf name cannot be null";
    assert !clientItfName.equals("") : "Client itf name cannot be empty";
    
    this.client=client;
    this.clientItfName=clientItfName;
  }
  
  public void execute() throws DeploymentException {
    //log("execute :" +toString());
    try{
    BindingNotificationController bnc = Reflex.getBindingNotificationController(client);
    bnc.unbindFcNotification(clientItfName);
    }catch(NoSuchInterfaceException e){
      throw new DeploymentException("BindTask error", e);
    } catch (IllegalBindingException e) {
      throw new DeploymentException("BindTask error", e);
    } catch (IllegalLifeCycleException e) {
      throw new DeploymentException("BindTask error", e);
    }
  }

  public String getLevelName(){
    return "cleanBinding";
  }
  
  public String toString(){
    return 
      "CleanBindingTask[" +
      client + "." + clientItfName + "]";
  }
}
